home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions Quickprop component
-
- #include "NSDLL.h"
-
- /*****************************/
- /* Gradient search procedure */
-
- __declspec(dllexport) void performQuickprop(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *weights, // Pointer to the vector of weights
- int length, // Length of the weight vector
- NSFloat *gradient, // Pointer to the vector of gradients, one for each weight
- NSFloat *step, // Pointer to the learning rate/s
- BOOL individual, // Indicates whether their is one learning rate for all weights (FALSE),
- // or each weight has its own learning rate
- int stepDivisor,// The number each step size should be divided by
- BOOL decayWeights, // TRUE if weight decay is active
- NSFloat decayRate, // Rate to decay weights if weight decay is active
- NSFloat *delta, // Last weight Update
- NSFloat *momentum, // Individual momentum rate for each weight
- NSFloat defaultMomentum, // Max momentum rate for all weights
- NSFloat *lastGradient // Previous weight gradient vector
- )
- {
- register int i;
-
- for (i=0; i<length; i++) {
- momentum[i] = gradient[i]/(lastGradient[i] - gradient[i]);
- if (momentum[i] > defaultMomentum)
- momentum[i] = defaultMomentum;
- if (momentum[i] < -defaultMomentum)
- momentum[i] = -defaultMomentum;
- delta[i] = momentum[i]*delta[i] + lastGradient[i]*(gradient[i]<0?0:(step[individual?i:0]/stepDivisor)*gradient[i]);
- weights[i] += delta[i] - (decayWeights ? weights[i] * decayRate : 0.0f);
- lastGradient[i] = gradient[i];
- }
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocQuickprop(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int length, // Length of the weight vector
- BOOL individual // Indicates whether their is one learning rate for all weights (FALSE),
- // or each weight has its own learning rate
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeQuickprop(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */